home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1994 / MacHack 1994.toast / MacHack™ 1987-1994 / MacHack™ '87 / Source ƒ.sea / Source ƒ / emacs source ƒ / IBMPC.C < prev    next >
Encoding:
C/C++ Source or Header  |  1992-06-28  |  6.3 KB  |  301 lines  |  [TEXT/MARC]

  1. /*
  2.  * The routines in this file provide support for the IBM-PC and other
  3.  * compatible terminals. It goes directly to the graphics RAM to do
  4.  * screen output. It compiles into nothing if not an IBM-PC driver
  5.  */
  6.  
  7. #define    termdef    1            /* don't define "term" external */
  8.  
  9. #include        <stdio.h>
  10. #include    "estruct.h"
  11. #include        "edef.h"
  12.  
  13. #if     (IBMPC | IBMMONO)
  14.  
  15. #define NROW    25                      /* Screen size.                 */
  16. #define NCOL    80                      /* Edit if you want to.         */
  17. #define    MARGIN    8            /* size of minimim margin and    */
  18. #define    SCRSIZ    64            /* scroll size for extended lines */
  19. #define    NPAUSE    200            /* # times thru update to pause */
  20. #define BEL     0x07                    /* BEL character.               */
  21. #define ESC     0x1B                    /* ESC character.               */
  22. #define    SPACE    32            /* space character        */
  23.  
  24. #if    IBMPC
  25. #define    SCADD    0xb8000000L        /* address of screen RAM    */
  26. #else
  27. #define    SCADD    0xb0000000L        /* address of screen RAM    */
  28. #endif
  29.  
  30. int *scptr[NROW];            /* pointer to screen lines    */
  31. int sline[NCOL];            /* screen line image        */
  32.  
  33. extern  int     ttopen();               /* Forward references.          */
  34. extern  int     ttgetc();
  35. extern  int     ttputc();
  36. extern  int     ttflush();
  37. extern  int     ttclose();
  38. extern  int     ibmmove();
  39. extern  int     ibmeeol();
  40. extern  int     ibmeeop();
  41. extern  int     ibmbeep();
  42. extern  int     ibmopen();
  43. extern    int    ibmrev();
  44. extern    int    ibmclose();
  45. extern    int    ibmputc();
  46. extern    int    ibmkopen();
  47. extern    int    ibmkclose();
  48.  
  49. #if    COLOR
  50. extern    int    ibmfcol();
  51. extern    int    ibmbcol();
  52.  
  53. int    cfcolor = -1;        /* current forground color */
  54. int    cbcolor = -1;        /* current background color */
  55. int    ctrans[] =        /* ansi to ibm color translation table */
  56.     {0, 4, 2, 6, 1, 5, 3, 7};
  57. #endif
  58.  
  59. /*
  60.  * Standard terminal interface dispatch table. Most of the fields point into
  61.  * "termio" code.
  62.  */
  63. TERM    term    = {
  64.         NROW-1,
  65.         NCOL,
  66.     MARGIN,
  67.     SCRSIZ,
  68.     NPAUSE,
  69.         ibmopen,
  70.         ibmclose,
  71.     ibmkopen,
  72.     ibmkclose,
  73.         ttgetc,
  74.     ibmputc,
  75.         ttflush,
  76.         ibmmove,
  77.         ibmeeol,
  78.         ibmeeop,
  79.         ibmbeep,
  80.     ibmrev
  81. #if    COLOR
  82.     , ibmfcol,
  83.     ibmbcol
  84. #endif
  85. };
  86.  
  87. extern union REGS rg;
  88.  
  89. #if    COLOR
  90. ibmfcol(color)        /* set the current output color */
  91.  
  92. int color;    /* color to set */
  93.  
  94. {
  95.     cfcolor = ctrans[color];
  96. }
  97.  
  98. ibmbcol(color)        /* set the current background color */
  99.  
  100. int color;    /* color to set */
  101.  
  102. {
  103.         cbcolor = ctrans[color];
  104. }
  105. #endif
  106.  
  107. ibmmove(row, col)
  108. {
  109.     rg.h.ah = 2;        /* set cursor position function code */
  110.     rg.h.dl = col;
  111.     rg.h.dh = row;
  112.     rg.h.bh = 0;        /* set screen page number */
  113.     int86(0x10, &rg, &rg);
  114. }
  115.  
  116. ibmeeol()    /* erase to the end of the line */
  117.  
  118. {
  119.     int attr;    /* attribute byte mask to place in RAM */
  120.     int *lnptr;    /* pointer to the destination line */
  121.     int i;
  122.     int ccol;    /* current column cursor lives */
  123.     int crow;    /*       row    */
  124.  
  125.     /* find the current cursor position */
  126.     rg.h.ah = 3;        /* read cursor position function code */
  127.     rg.h.bh = 0;        /* current video page */
  128.     int86(0x10, &rg, &rg);
  129.     ccol = rg.h.dl;        /* record current column */
  130.     crow = rg.h.dh;        /* and row */
  131.  
  132.     /* build the attribute byte and setup the screen pointer */
  133. #if    COLOR
  134.     attr = (((cbcolor & 15) << 4) | (cfcolor & 15)) << 8;
  135. #else
  136.     attr = 0x0700;
  137. #endif
  138.     lnptr = &sline[0];
  139.     for (i=0; i < NCOL; i++)
  140.         *lnptr++ = SPACE | attr;
  141.  
  142. #if    FLICKER
  143.     /* wait for vertical retrace to be off */
  144.     while ((inp(0x3da) & 8))
  145.         ;
  146.  
  147.     /* and to be back on */
  148.     while ((inp(0x3da) & 8) == 0)
  149.         ;
  150. #endif
  151.  
  152.     /* and send the string out */
  153.     movmem(&sline[0], scptr[crow]+ccol, (NCOL-ccol)*2);
  154.  
  155. }
  156.  
  157. ibmputc(ch)    /* put a character at the current position in the
  158.            current colors */
  159.  
  160. int ch;
  161.  
  162. {
  163.     rg.h.ah = 14;        /* write char to screen with current attrs */
  164.     rg.h.al = ch;
  165. #if    COLOR
  166.     rg.h.bl = cfcolor;
  167. #else
  168.     rg.h.bl = 0x07;
  169. #endif
  170.     int86(0x10, &rg, &rg);
  171. }
  172.  
  173. ibmeeop()
  174. {
  175.     int attr;        /* attribute to fill screen with */
  176.  
  177.     rg.h.ah = 6;        /* scroll page up function code */
  178.     rg.h.al = 0;        /* # lines to scroll (clear it) */
  179.     rg.x.cx = 0;        /* upper left corner of scroll */
  180.     rg.x.dx = 0x174f;    /* lower right corner of scroll */
  181. #if    COLOR
  182.     attr = ((ctrans[gbcolor] & 15) << 4) | (ctrans[gfcolor] & 15);
  183. #else
  184.     attr = 0;
  185. #endif
  186.     rg.h.bh = attr;
  187.     int86(0x10, &rg, &rg);
  188. }
  189.  
  190. ibmrev(state)        /* change reverse video state */
  191.  
  192. int state;    /* TRUE = reverse, FALSE = normal */
  193.  
  194. {
  195.     /* This never gets used under the IBM-PC driver */
  196. }
  197.  
  198. ibmbeep()
  199. {
  200.     bdos(6, BEL, 0);
  201. }
  202.  
  203. ibmopen()
  204. {
  205.     scinit();
  206.     revexist = TRUE;
  207.         ttopen();
  208. }
  209.  
  210. ibmclose()
  211.  
  212. {
  213. #if    COLOR
  214.     ibmfcol(7);
  215.     ibmbcol(0);
  216. #endif
  217.     ttclose();
  218. }
  219.  
  220. ibmkopen()    /* open the keyboard */
  221.  
  222. {
  223. }
  224.  
  225. ibmkclose()    /* close the keyboard */
  226.  
  227. {
  228. }
  229.  
  230. scinit()    /* initialize the screen head pointers */
  231.  
  232. {
  233.     union {
  234.         long laddr;    /* long form of address */
  235.         int *paddr;    /* pointer form of address */
  236.     } addr;
  237.     int i;
  238.  
  239.     /* initialize the screen pointer array */
  240.     for (i = 0; i < NROW; i++) {
  241.         addr.laddr = SCADD + (long)(NCOL * i * 2);
  242.         scptr[i] = addr.paddr;
  243.     }
  244. }
  245.  
  246. scwrite(row, outstr, forg, bacg)    /* write a line out*/
  247.  
  248. int row;    /* row of screen to place outstr on */
  249. char *outstr;    /* string to write out (must be NCOL long) */
  250. int forg;    /* forground color of string to write */
  251. int bacg;    /* background color */
  252.  
  253. {
  254.     int attr;    /* attribute byte mask to place in RAM */
  255.     int *lnptr;    /* pointer to the destination line */
  256.     int i;
  257.  
  258.     /* build the attribute byte and setup the screen pointer */
  259. #if    COLOR
  260.     attr = (((ctrans[bacg] & 15) << 4) | (ctrans[forg] & 15)) << 8;
  261. #else
  262.     attr = (((bacg & 15) << 4) | (forg & 15)) << 8;
  263. #endif
  264.     lnptr = &sline[0];
  265.     for (i=0; i<NCOL; i++)
  266.         *lnptr++ = (outstr[i] & 255) | attr;
  267.  
  268. #if    FLICKER
  269.     lflick++;
  270.     if (lflick >= NFLICK) {
  271.         /* wait for vertical retrace to be off */
  272.         while ((inp(0x3da) & 8))
  273.             ;
  274.  
  275.         /* and to be back on */
  276.         while ((inp(0x3da) & 8) == 0)
  277.             ;
  278.         lflick = 0;
  279.     }
  280. #endif
  281.  
  282.     /* and send the string out */
  283.     movmem(&sline[0], scptr[row],NCOL*2);
  284. }
  285.  
  286. #if    FLABEL
  287. fnclabel(f, n)        /* label a function key */
  288.  
  289. int f,n;    /* default flag, numeric argument [unused] */
  290.  
  291. {
  292.     /* on machines with no function keys...don't bother */
  293.     return(TRUE);
  294. }
  295. #endif
  296. #else
  297. ibmhello()
  298. {
  299. }
  300. #endif
  301.